# 直接插入排序法  自己搞的 比书上复杂好多
# 逐一比较列表中的数, 并逐一按顺序插入到合适的位置

from utils.random_list import sjlb
from utils.array_utils import insert_left_by_list
from utils.array_utils import find_small
from utils.array_utils import check


def insert(arr):
    arr_new = len(arr) * [None]
    for i in range(len(arr)):
        arr_new[i] = arr[i]
        small_index = find_small(arr_new, i)
        insert_left_by_list(arr_new, small_index, i)
    return arr_new


if __name__ == '__main__':
    for i in range(1000):
        l = sjlb()
        # l = [0, 13, 17, 0]
        # # l = [13, 8, 11, 20, 17]
        # print(l)
        new_l = insert(l)
        if not check(new_l):
            print(new_l)


